<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <title>重置密码</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/iconfont/iconfont.css" rel="stylesheet"/>
    <link href="css/common.css" rel="stylesheet"/>
    <link href="css/login.css" rel="stylesheet"/>
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<!--头部-->
    <div class="login-header">
        <div class="wrapper">
            <a href="" class="logo">
                <img src="img/logo3.png" alt="" />
            </a>
            <div class="zp">
                <span class="ico"></span>
                <div>正品保障</div>
            </div>
        </div>
    </div>
    <div class="main-wrap">
        <div class="wrapper">
            <div class="center-box">
                <form action="" method="">
                    <div class="box-hd">
                        <span class="tit">重置密码</span>
                    </div>
                    <label class="txtin-box">
                        <input class="txtin" type="" name="username" placeholder="输入用户名" />
                    </label>
                    <label class="txtin-box">
                        <input class="txtin" type="password" name="password" placeholder="输入密码" />
                    </label>
                    <label class="txtin-box">
                        <input class="txtin" type="password" name="rePassword" placeholder="确认密码" />
                    </label>

                    <button class="layui-btn layui-bg-red layui-btn-fluid" lay-submit lay-filter="resetPwd">修&ensp;改</button>

                </form>
            </div>
        </div>
    </div>
    <div class="login-footer">
        <div class="authentication">

        </div>
    </div>
</body>
<script src="js/jquery.js"></script>
<script src="js/global.js"></script>
<script src="/layui/layui.js"></script>
<script>
    //JS
    layui.use([ 'layer', 'form'], function () {
        var layer = layui.layer;
        var $ = layui.$;
        var form = layui.form;

        //表单的提交操作
        form.on('submit(resetPwd)', function (data) {
            //手动获取表单数据
            var username = $('[name="username"]').val();
            var password = $('[name="password"]').val();
            var rePassword = $('[name="rePassword"]').val();
            //ajax 发送修改密码的请求
            $.ajax({
                url: '/api/rePassword',//请求路径
                data: {username, password, rePassword},//要传递参数
                type: 'post',//http的请求方式
                dataType: 'json',//返回数据类型
                success: function (result) {//成功的回调 result服务器返回的数据
                    if (result.code == 0) {
                        //成功
                        layer.msg("修改成功", {icon: 6}, function (index) {
                            //跳转到登录页面
                            window.location.href = '/';
                        });
                    } else {
                        //失败
                        layer.msg(result.msg, {icon: 5})
                    }
                },
                error: function () {
                    layer.msg('请求失败', {icon: 5});
                }
            });

            //阻止表单的自动提交
            return false;
        });
    });
</script>
</html>